package ua.maxicash.vo;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.hibernate.annotations.*;

@Entity
@Table(name = "JobType")
@JsonIgnoreProperties({"workers","employers"})
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class JobType {

	@Id
	@Column(name = "ID_JOB")
	@GeneratedValue
	private Long idJob;
	
	@Column(name = "title")
	private String title;
	
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "Worker_JobType", joinColumns = {@JoinColumn(name = "ID_Job")}, 
			inverseJoinColumns = {@JoinColumn(name = "ID_USER")})
	@org.hibernate.annotations.Cascade(value={org.hibernate.annotations.CascadeType.SAVE_UPDATE}) 
	//@LazyCollection(LazyCollectionOption.FALSE)
	private List<Worker> workers = new ArrayList<Worker>();

    @ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "Employer_JobType", joinColumns = {@JoinColumn(name = "ID_Job")},
			inverseJoinColumns = {@JoinColumn(name = "ID_USER")})
	@org.hibernate.annotations.Cascade(value={org.hibernate.annotations.CascadeType.SAVE_UPDATE})
	//@LazyCollection(LazyCollectionOption.FALSE)
	private List<Employer> employers = new ArrayList<Employer>();

	public JobType() {
	}

	public Long getIdJob() {
		return idJob;
	}

	public void setIdJob(Long idJob) {
		this.idJob = idJob;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	
	public List<Worker> getWorkers() {
		return workers;
	}

	public void setWorkers(List<Worker> workers) {
		this.workers = workers;
	}

    public List<Employer> getEmployers() {
        return employers;
    }

    public void setEmployers(List<Employer> employers) {
        this.employers = employers;
    }

    @Override
	public String toString() {
		return "JobType [idJob=" + idJob + ", title=" + title + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((idJob == null) ? 0 : idJob.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		JobType other = (JobType) obj;
		if (idJob == null) {
			if (other.idJob != null)
				return false;
		} else if (!idJob.equals(other.idJob))
			return false;
		return true;
	}

    


	

	// ID_JOB TITLE

}
